// tslint:disable-next-line:no-reference
/// <reference path="typings/isc/isc.index.d.ts" />
import { $log} from "ts-log-debug";
import { IKey, KeyBox} from "./KeyBox";
import { KeyListPane} from "./KeyListPane";
import { MainPasswordWindow} from "./MainPasswordWindow";

let keyBox: KeyBox;

// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.

$log.appenders.set("stdlog", {
    levels: ["debug", "info", "trace"],
    type: "stdout",
  }).set("fileout", {
    filename: KeyBox.getWorkPath() + "./app.log",
    layout: {type: "basic"},
    type: "file",
  });
isc.Log.useChromeAPIToPrepareStackTrace = false;
isc.Log.logInfo = ( msg: string, category?: string) => {
    $log.info( msg);
};
isc.Log.logWarn = ( msg: string, category?: string) => {
    $log.warn( msg);
};
isc.Log.logError = ( msg: string, category?: string) => {
    $log.error( msg);
};

window.onload = () => {
    isc.Canvas.resizeFonts(3);
    keyBox = KeyBox.load();
    const keyListPane = new KeyListPane( keyBox);
    if ( keyBox == null) {
        const mainPassWnd = new MainPasswordWindow( keyListPane);
        mainPassWnd.showCreateMainPasswordWindow();
    } else {
        keyListPane.showKeyTables();
    }
};
